import { defineStore } from "pinia";
import { GlobalState } from "@/stores/types";
import piniaPersistConfig from "@/stores/helper/persist";

export const useGlobalStore = defineStore({
  id: "app-global",
  // 修改默认值之后，需清除 localStorage 数据
  state: (): GlobalState => ({
    // 当前页面是否全屏
    maximize: false,
    // 当前系统语言
    language: null,
    // 折叠菜单
    isCollapse: false,
    // 菜单手风琴
    accordion: true,
    // 面包屑导航
    breadcrumb: true,
    // 面包屑导航图标
    breadcrumbIcon: true,
    // 标签页
    tabs: true,
    // 标签页图标
    tabsIcon: true
  }),
  getters: {},
  actions: {
    // Set GlobalState
    setGlobalState(key: keyof GlobalState, val: GlobalState[keyof GlobalState]) {
      this.$patch({ [key]: val });
    }
  },
  persist: piniaPersistConfig("app-global")
});
